package com.windfone.web;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.windfone.model.Ad;
import com.windfone.service.CommonService;

public   class AdTag extends TagSupport {
	/**	serialVersionUID */
	private static final long serialVersionUID = 1L;
	private CommonService commonService;
	private String attriName;
	private String flag;
	private List<Ad> ads;
	
	
	public CommonService getCommonService() {
		return commonService;
	}

	public String getAttriName() {
		return attriName;
	}

	public String getFlag() {
		return flag;
	}

	public List<Ad> getAds() {
		return ads;
	}

	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}

	public void setAttriName(String attriName) {
		this.attriName = attriName;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public void setAds(List<Ad> ads) {
		this.ads = ads;
	}

	public int doStartTag() throws JspException {
		ServletContext sc = pageContext.getServletContext();
		if ( commonService == null )
			commonService = (CommonService) WebApplicationContextUtils.getWebApplicationContext(sc).getBean("commonService");
		if ( attriName != null ){
			ads = commonService.getAdsByFlag(flag);
			this.pageContext.setAttribute(attriName,ads);
		}
		return(SKIP_BODY);
 
	}
}
